package com.chinasoft04.mall.controller;

import com.chinasoft04.mall.service.OrderService;
import com.chinasoft04.mall.dto.Rbody;
import lombok.AllArgsConstructor;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@AllArgsConstructor
@RequestMapping("/api/private/v1")
public class OrderController {

    OrderService orderService;

    @GetMapping("/orders")
    public Rbody getOrders(@Nullable String query, Integer pagenum, Integer pagesize){
        Rbody rbody = new Rbody();
        Object orders = orderService.getOrders(query, pagenum, pagesize);
        if (orders != null){
           rbody.setData(orders);
           rbody.getMeta().setMsg("获取成功");
        }else {
            rbody.getMeta().setMsg("获取失败");
            rbody.getMeta().setStatus(500);
        }
        return rbody;
    }
}